#include "Camera.h"
#include "InputMgr.h"

Camera::Camera()
: m_targetPos(1.0f, 1.0f, 1.0f)
{
}

Camera::~Camera()
{
}

void Camera::GetViewMatrix(D3DXMATRIX& a_outViewMat)
{
	D3DXVECTOR3 upVec = GetUpVec();
	D3DXMatrixLookAtLH(&a_outViewMat, &m_eyePos, &m_targetPos, &upVec);
}

D3DXVECTOR3 Camera::GetUpVec() const
{
	// Note: Up vector remains the same regardless of camera orientation (if no roll)
	return D3DXVECTOR3(0.0f, 1.0f, 0.0f);
}


void Camera::Update(float a_dt)
{
	if (m_pAttached)
	{
		// Camera is attached to an object - follow it
		float speed = 4.0f;
		D3DXVECTOR3 desiredEyePos = m_pAttached->GetCameraAttachPos();
		D3DXVECTOR3 dist =  desiredEyePos - m_eyePos;
		m_eyePos += dist * a_dt * speed;
	}
	if (m_pTracked)
	{
		//Lerp 
		float speed = 4.0f;
		D3DXVECTOR3 desiredTargetPos = m_pTracked->GetCameraTrackPos();
		D3DXVECTOR3 dist =  desiredTargetPos - m_targetPos;
		m_targetPos += dist * a_dt * speed;
	}
}